using System;

namespace Phoenix.Framework
{
    public class DefaultControllerFactory : ControllerFactoryBase
    {
        protected override T CreateController<T>()
        {
            return Activator.CreateInstance<T>();
        }

        protected override Controller CreateController(Type controllerType)
        {
            return (Controller)Activator.CreateInstance(controllerType);
        }

        public override void Release(Controller controller)
        {
            // ReSharper disable SuspiciousTypeConversion.Global
            var disposible = controller as IDisposable;
            if (disposible != null)
                disposible.Dispose();
            // ReSharper restore SuspiciousTypeConversion.Global
        }
    }
}